package framework.entity;

import java.util.ArrayList;
import java.util.StringTokenizer;

public class ACLFunction extends ACLEntity{

	public static String ACL_FUNCTION = "ACLFUNCTION";
	
	private ArrayList<String> in;

	private String out;



	private Boolean isAbstract;




	static public int MODE1 = 0;
	static public int MODE2 = 1;

	public ACLFunction(String name) {
		super(name);
		in = new ArrayList<String>();
		out = "void";
	}

	public ACLFunction(String str, int mode) {

		super(str.substring(0, str.indexOf('(')));

		in = new ArrayList<String>();

		String strIn = str
		.substring(str.indexOf('(') + 1, str.indexOf(')'));
		StringTokenizer tok = new StringTokenizer(strIn, " ");
		while (tok.hasMoreTokens()) {
			String t = tok.nextToken();
			in.add(t);
		}
		String strOut = str.substring(str.indexOf(':') + 1);
		tok = new StringTokenizer(strOut, " ");
		out = tok.nextToken();
		

	
}

public ArrayList<String> getIn() {
	return in;
}

public String getOut() {
	return out;
}

public void addIn(String s) {
	in.add(s);
}

public void addOut(String s) {
	out = s;
}



public void replaceIn(String s1, String s2) {
	in.remove(s1);
	in.add(s2);
}

public boolean equals(Object o1) {
	ACLFunction op = (ACLFunction) o1;
	return equals(this, op);
}

public Boolean isAbstract(){return isAbstract;}

public void setAbstract(Boolean b){isAbstract = b;}


public Boolean equals(ACLFunction o1, ACLFunction o2) {
	Boolean result = true;
	if (!o1.getName().equals(o2.getName()))
		return false;
	if (o1.getIn().size() != o2.getIn().size())
		return false;
	if (o1.getOut() != o2.getOut())
		return false;
	for (int i = 0; i < o1.getIn().size(); i++) {
		if (!o2.getIn().contains(o1.getIn().get(i)))
			return false;
	}

	return true;
}

public String toString() {
	String result = name + "( ";
	for (int i = 0; i < in.size(); i++) {
		result = result + in.get(i) + " ";
	}
	result = result + "): ";
	result = result + out;

	return result;
}

@Override
public String getType() {
	// TODO Auto-generated method stub
	return ACL_FUNCTION;
}
}
